Look at the residence permit itself. The residence permit states its own period of validity and the duration of each stay; it is that expiry date, not the visa or passport date, that governs your legal stay.
Nationwide (all cities)
The date on the residence permit
The date you must watch is the one printed on your residence permit, not the one on your visa or passport.
Residence permit vs visa
A residence permit and a visa are different documents. Under the Exit and Entry Administration Law, the residence permit states its own period of validity and the duration of each stay. When your work permit and residence permit were issued, the residence permit's validity was set together with your employment, but it is the residence permit itself that shows the date by which you must renew.
Do not confuse the three dates
Do not confuse the three dates. Your passport has an expiry date; your visa (if you still rely on one) has an entry validity; and your residence permit has its own validity and stay period. What matters for staying legally is the residence permit's expiry date and the permitted duration of stay it states.
Count back from that date
So locate the expiry date directly on the residence permit. That is the date you count back from — the rules require you to apply for renewal within 30 days before that date.